<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true"%>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="jakarta.tags.core" %>
<%@ taglib prefix="ujn" uri="http://ujn.edu.cn/common/"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName()
            + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML>
<html>

<head>
    <title>coupon.jsp</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- 引入css样式文件 -->
    <!-- Bootstrap Core CSS -->
    <link href="<%=basePath%>css/bootstrap.css" rel="stylesheet"/>
    <!-- Bootstrap-grid CSS -->
    <link href="<%=basePath%>css/bootstrap-grid.css" rel="stylesheet"/>
    <!-- Bootstrap-reboot CSS -->
    <link href="<%=basePath%>css/bootstrap-reboot.css" rel="stylesheet"/>
    <!-- MetisMenu CSS -->
    <link href="<%=basePath%>css/metisMenu.min.css" rel="stylesheet" />
    <!-- DataTables CSS -->
    <link href="<%=basePath%>css/dataTables.bootstrap.css" rel="stylesheet" />
    <!-- Custom CSS -->
    <link href="<%=basePath%>css/sb-admin-2.css" rel="stylesheet" />
    <!-- Custom Fonts -->
    <link href="<%=basePath%>css/font-awesome.min.css" rel="stylesheet" type="text/css" />
    <link href="<%=basePath%>css/boot-crm.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>

<div>
    <nav class="navbar navbar-expand-lg navbar-dark " style="background-color:#81D8CF;;">
        <img src="imges/logo.jpg" class="rounded float-left" alt="Logo" height="45" width="45">
        <div class="container" style="">
            <a class="navbar-brand" href="#">停车场管理系统</a>
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText"
                    aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarText">
                <ul class="navbar-nav mr-auto">
                    <li class="nav-item">
                        <a class="nav-link " href="${pageContext.request.contextPath }/userself">个人信息</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link " href="${pageContext.request.contextPath }/bookself">车位预定</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="${pageContext.request.contextPath}/payments">全部订单</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link active" href="${pageContext.request.contextPath}/coupon">优惠券</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="${pageContext.request.contextPath }/rateself">收费标准</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="${pageContext.request.contextPath }/vehicleself">车辆信息</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="${pageContext.request.contextPath }/userequip">投诉反馈</a>
                    </li>
                </ul>
                <span class="navbar-text">
          导航栏
        </span>
            </div>
        </div>
    </nav>
</div>

<%
    if (session.getAttribute("USER_SESSION") != null) {
%>
<!-- 登录成功界面 -->

<!-- 兑换优惠券按钮 -->
<div class="container" style="margin-top: 20px;">
    <button type="button" class="btn btn-light" onclick="openAcquireModal()">兑换优惠券</button>
    <span id="message">${msg}</span>    <!-- 显示提示信息 -->
</div>

<!-- 优惠券展示列表 -->
<div class="container" style="padding-top: 20px; padding-bottom: 30px; text-align: center; background-color: rgba(255, 255, 255, 0.7);">
    <table class="table table-striped">
        <thead>
        <tr>
            <th>优惠券ID</th>
            <th>优惠券码</th>
            <th>价值</th>
            <th>是否有效</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${page.rows}" var="coupon">
            <tr>
                <td>${coupon.couponId}</td>
                <td>${coupon.code}</td>
                <td>${coupon.value}</td>
                <td>
                    <c:choose>
                        <c:when test="${coupon.isActive}">
                            有效
                        </c:when>
                        <c:otherwise>
                            无效
                        </c:otherwise>
                    </c:choose>
                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
    <!-- 分页组件 -->
    <div class="col-md-12 text-right">
        <ujn:page url="${pageContext.request.contextPath}/coupon"/>
    </div>
</div>

<div class="modal fade" id="acquireCouponModal" tabindex="-1" role="dialog" aria-labelledby="acquireCouponModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <!-- 表单，提交到固定的路径 -->
            <form id="acquireCouponForm" method="post" action="${pageContext.request.contextPath}/couponAcquire">
                <div class="modal-header">
                    <h5 class="modal-title" id="acquireCouponModalLabel">兑换优惠券</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="关闭">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <!-- 输入优惠券ID -->
                    <div class="form-group">
                        <label for="couponIdInput">请输入优惠券ID：</label>
                        <input type="text" class="form-control" id="couponIdInput" name="code" required>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="submit" class="btn btn-primary">确认兑换</button>
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                </div>
            </form>
        </div>
    </div>
</div>


<%
} else{
%>
<!--登陆失败界面-->
<div class="jumbotron jumbotron-fluid">
    <div class="container">
        <h1 class="display-4">欢迎您,登录后即可查看</h1>
        <p class="lead">
            <a href="${pageContext.request.contextPath}/login">Welcome, log in to view</a>
        </p>
    </div>
</div>
<%  }
%>

<!-- 引入js文件 -->
<script src="<%=basePath%>js/jquery-1.11.3.min.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="<%=basePath%>js/bootstrap.js"></script>
<!-- Bootstrap-bundle JavaScript -->
<script src="<%=basePath%>js/bootstrap.bundle.js"></script>
<!-- Metis Menu Plugin JavaScript -->
<script src="<%=basePath%>js/metisMenu.min.js"></script>
<!-- DataTables JavaScript -->
<script src="<%=basePath%>js/jquery.dataTables.min.js"></script>
<script src="<%=basePath%>js/dataTables.bootstrap.min.js"></script>
<!-- Custom Theme JavaScript -->
<script src="<%=basePath%>js/sb-admin-2.js"></script>


<script>
    function openAcquireModal() {
        $('#acquireCouponModal').modal('show');
    }
</script>

</body>
</html>
